package org.genntii.warehousesystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.genntii.warehousesystem.domain.entity.WareHouse;

import java.time.LocalDateTime;
import java.util.List;


@Mapper
public interface WarehouseMapper extends BaseMapper<WareHouse> {

    @Update("update warehouse set status = 0, last_update_time = #{time} where id = #{id}")
    void del(@Param("id")int id, @Param("time")LocalDateTime time);

    @Update("update warehouse set status = 1, last_update_time = #{time} where id = #{id}")
    void enable(@Param("id")int id, @Param("time")LocalDateTime time);

    @Update("update warehouse set name = #{name}," +
            "city_id = #{cityId}," +
            "address = #{address}," +
            "postcode = #{postcode}," +
            "phone = #{phone}," +
            "status = #{status}," +
            "last_update_time = #{time} where id = #{id}")
    void update(@Param("id")int id,
                @Param("name")String name,
                @Param("cityId")int cityId,
                @Param("address")String address,
                @Param("postcode")String postcode,
                @Param("phone")String phone,
                @Param("status")int status,
                @Param("time")LocalDateTime time);

    @Select("select * from warehouse where status = 1 limit #{from}, 10")
    List<WareHouse> findAllEnable(@Param("from")int from);

    @Select("select * from warehouse where status = 0 limit #{from}, 10")
    List<WareHouse> findAllUnable(@Param("from")int from);

    @Select("select * from warehouse where city_id = #{id}")
    WareHouse findByCity(@Param("id")int id);





}
